import { defHttp } from '/@/utils/http/axios';
import {
  DemoParams,
  HouseCheckPageParams,
  DemoListGetResultModel,
  HouseListGetResultModel,
} from './model/tableModel';

enum Api {
  DEMO_LIST = '/table/getDemoList',
  GRAFFITI_LIST = '/graffiti/list',
  GRAFFITI_INFO = '/graffiti/list',
  TRACK_INFO = '/graffiti/list',
  PHOTO_LIST = '/photo/list',
  HOUSE_LIST = '/houses/search-attr',
  HOUSE_LISTjb = '/houses/search-attrjb',
  YT_LIST = '/yt/search-attr-build-body', // 阳台排查 -- 楼栋列表
  VILLAGE_LIST = '/villages/search-attr',
  VILLAGE_LISTyj = '/villages/search-attryj',
  VILLAGE_LIST_314 = '/villages/search-attr_314',
  VILLAGE_EXPORT = '/villages/ExportExcel',
  VILLAGE_EXPORT_all = '/villages/ExportExcelall',
}

/**
 * @description: Get sample list value
 */

export const supplementListApi = (params: DemoParams) =>
  Promise.resolve({
    items: [],
    total: 0,
  });

export const demoListApi = (params: DemoParams) =>
  defHttp.get<DemoListGetResultModel>({
    url: Api.DEMO_LIST,
    params,
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const houseCheckListApi = (params: HouseCheckPageParams) =>
  defHttp.get<DemoListGetResultModel>({
    url: `/sample-tasks/${params.id}/search-attr`,
    params: {
      pageIndex: params.page - 1,
      limit: params.pageSize,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const detailLastCheckApi = (params: any) =>
  defHttp.get<HouseListGetResultModel>(
    {
      url: `/sample-tasks/houses/${params.hid}/check-result/last`,
      params: {
        id: params.hid,
      },
      headers: {
        // @ts-ignore
        ignoreCancelToken: true,
      },
    },
    {
      errorMessageMode: 'none',
    },
  );

export const houseCheckApi = (params: any) =>
  defHttp.get<HouseListGetResultModel>(
    {
      url: `/sample-tasks/houses/${params.id}/info`,
      params: {
        id: params.id,
      },
      headers: {
        // @ts-ignore
        ignoreCancelToken: true,
      },
    },
    { errorMessageMode: 'none' },
  );
//// 自建房-核查任务管理(市级) --- 核查情况的搜索 接口
export const houseCityCheckListApi = (params: HouseCheckPageParams) =>
  defHttp.get<DemoListGetResultModel>({
    url: `/city-sample-tasks/${params.id}/search-attr`,
    params: {
      pageIndex: params.page - 1,
      limit: params.pageSize,
      ...params,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
// 非住宅-核查任务管理(市级)--核查情况(查询list)
export const houseCityFzzListApi = (params: HouseCheckPageParams) =>
  defHttp.get<DemoListGetResultModel>({
    url: `/city-sample-tasks/${params.id}/search-attr_fzz`,
    params: {
      pageIndex: params.page - 1,
      limit: params.pageSize,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const houseByCityCheckListApi = (params: HouseCheckPageParams) =>
  defHttp.get<DemoListGetResultModel>({
    url: `/risk-census-house/sampled-by-city`,
    params: {
      pageIndex: params.page - 1,
      limit: params.pageSize,
      ...params,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const detailCityLastCheckApi = (params: any) =>
  defHttp.get<HouseListGetResultModel>(
    {
      url: `/city-sample-tasks/houses/${params.hid}/check-result/last`,
      params: {
        id: params.hid,
      },
      headers: {
        // @ts-ignore
        ignoreCancelToken: true,
      },
    },
    {
      errorMessageMode: 'none',
    },
  );

export const houseCityCheckApi = (params: any) =>
  defHttp.get<HouseListGetResultModel>({
    url: `/city-sample-tasks/houses/${params.id}/info`,
    params: {
      id: params.id,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
// 非住宅 -- 获取房屋信息
export const houseCityFzzApi = (params: any) =>
  defHttp.get<HouseListGetResultModel>({
    url: `/city-sample-tasks/houses/${params.id}/info_fzz`,
    params: {
      id: params.id,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const delCitySamplingHouseApi = (params: Recordable) =>
  defHttp.post(
    { url: `/city-sample-tasks/${params.id}/house-samples/${params.hid}/delete`, params: params },
    { errorMessageMode: 'modal', isReturnNativeResponse: true },
  );
// 非住宅 -- 删除
export const delCityFzzHouseApi = (params: Recordable) =>
  defHttp.post(
    {
      url: `/city-sample-tasks/${params.id}/house-samples/${params.hid}/delete_fzz`,
      params: params,
    },
    { errorMessageMode: 'modal' },
  );

  //获取隐患自查情况（历史纪录）
export const houseApi = (params: any) =>
  defHttp.get<HouseListGetResultModel>({
    url: `/houses/${params.id}/info`,
    params: {
      id: params.id,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

//获取房屋的自查信息
export const housrDetailApi = (params: any) =>
  defHttp.get<HouseListGetResultModel>({
    url: `/houses/${params.id}/restinfo`,
    params: {
      id: params.id,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
//获取房屋的最新的自查信息
export const housrApi = (params: any) =>
  defHttp.get<HouseListGetResultModel>({
    url: `/houses/${params.fwbh}/housrApi`,
    params: {
      fwbh: params.fwbh,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const housrYhDetailApi = (params: any) =>
  defHttp.get<HouseListGetResultModel>({
    url: `/houses/yhhourse/detail`,
    params: {
      id: params.id,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
//***************************************获取房屋的整改情况(lnn 2024-03-14)***************************************
export const housrRectificationApi = (params: any) =>
  defHttp.get({
    url: `/houses/ZgHousrRestinfo`,
    params: {
      id: params.id,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });


// ********************  获取某栋房子的某次检查情况******************村级工作进展明细（lnn） 2024-03-01  ********************
export const getCheckHousrDetailApi = (params: any) =>
  defHttp.get({
    url: `/village/${params.id}/restinfo`,
    params: {
      fwbh: params.id,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
export const VillageYhDetailApi = (params: any) =>
  defHttp.get<HouseListGetResultModel>({
    url: `/village/yhhourse/detail`,
    params: {
      id: params.id,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
// 获取阳台详情
export const balconyApi = (params: any) =>
  defHttp.get<HouseListGetResultModel>({
    url: `/Yt/GetZmYtBuildGeo2?build_no=${params.buildNo}`,
    params: {
      buildNo: params.buildNo,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
// 获取经营性自建房 详情
export const JyhouseApi = (params: any) =>
  defHttp.get<HouseListGetResultModel>({
    url: `/city-sample-tasks/search-attr-fw?id=${params.id}`,
    params: {
      buildNo: params.buildNo,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
export const houseZhujianApi = (params: any) =>
  defHttp.get<HouseListGetResultModel>({
    url: `/houses/${params.id}/zj-info`,
    params: {
      id: params.id,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const villageApi = (params: any) =>
  defHttp.get<HouseListGetResultModel>({
    url: `/villages/${params.id}/info`,
    params: {
      id: params.id,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const delVillage = (params: Recordable) =>
  defHttp.post(
    { url: `/villages/${params.id}/delete`, params: params },
    { errorMessageMode: 'modal' },
  );

export const delVillageyj = (params: Recordable) =>
  defHttp.post(
    { url: `/villages/${params.id}/deleteyj`, params: params },
    { errorMessageMode: 'modal' },
  );


export const trackApi = (params: any) =>
  defHttp.get<DemoListGetResultModel>({
    url: `/track/${params.id}/info`,
    params: {
      id: params.id,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const graffitiListApi = (params: DemoParams) =>
  defHttp.get<DemoListGetResultModel>({
    url: Api.GRAFFITI_LIST,
    params: {
      pageIndex: params.page - 1,
      limit: params.pageSize,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const photoListApi = (params: DemoParams) =>
  defHttp.get<DemoListGetResultModel>({
    url: Api.PHOTO_LIST,
    params: {
      pageIndex: params.page - 1,
      limit: params.pageSize,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

function buildDistricts(districts_) {
  const res: any[] = [];
  if (districts_) {
    districts_.forEach((element) => {
      if (element.length > 0) {
        res.push(JSON.parse(element[element.length - 1]));
      }
    });

    return res;
  }

  return [];
}
export const houseListApi = (params: any) =>
  defHttp.get({
    url: '/houses/search-attr',
    params: {
      ...params,
      districts: buildDistricts(params['districts_']),
      pageIndex: params.pageIndex - 1,
      limit: params.pageSize,
      orderBy: 0,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const otherhouseListApi = (params: any) =>
  defHttp.get({
    url: '/housessjhc/otherbaseYh',
    params: {
      ...params,
      districts: buildDistricts(params['districts_']),
      pageIndex: params.pageIndex - 1,
      limit: params.pageSize,
      orderBy: 0,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
  export const hyhousemcListApi = (params: any) =>
    defHttp.get({
      url: '/housesqjhc/otherbaseqjYh',
      params: {
        ...params,
        districts: buildDistricts(params['districts_']),
        pageIndex: params.pageIndex - 1,
        limit: params.pageSize,
        orderBy: 0,
      },
      headers: {
        // @ts-ignore
        ignoreCancelToken: true,
      },
    });
// export const houseListApi = (params: DemoParams) =>
//   defHttp.get({
//     url: Api.HOUSE_LIST,
//     data: {
//       ...params,
//       districts: buildDistricts(params['districts_']),
//       pageIndex: params.page - 1,
//       limit: params.pageSize,
//       orderBy: 0,
//     },
//     headers: {
//       // @ts-ignore
//       ignoreCancelToken: true,
//     },
//   });
  export const houseListApijb = (params: DemoParams) =>
  defHttp.post<DemoListGetResultModel>({
    url: Api.HOUSE_LISTjb,
    data: {
      ...params,
      districts: buildDistricts(params['districts_']),
      pageIndex: params.page - 1,
      limit: params.pageSize,
      orderBy: 0,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

//**************************************统计村级工作情况（lnn 2024-02-18）****************************************
export const villageProgreeApi = (params: DemoParams) =>
  defHttp.post<DemoListGetResultModel>({
    url: '/houses/evolvestatic/villagePostStatic',
    data: {
      ...params,
      districts: buildDistricts(params['districts_']),
      pageIndex: params.page,
      limit: params.pageSize,
      orderBy: 0,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
// 阳台管理 -- 阳台排查 -- 列表接口
export const balconyListApi = (params: DemoParams) =>
  defHttp.post<DemoListGetResultModel>({
    url: Api.YT_LIST,
    data: {
      ...params,
      districts: buildDistricts(params['districts_']),
      pageIndex: params.page - 1,
      limit: params.pageSize,
      orderBy: 0,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
export const villageListApi = (params: DemoParams) =>
  defHttp.post<DemoListGetResultModel>({
    url: Api.VILLAGE_LIST,
    data: {
      pczt: params.pczt,
      pageIndex: params.page - 1,
      limit: params.pageSize,
      orderBy: 0,
      districts: buildDistricts(params['districts_']),
      ...params,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

  export const villageListApiyj = (params: DemoParams) =>
  defHttp.post<DemoListGetResultModel>({
    url: Api.VILLAGE_LISTyj,
    data: {
      pczt: params.pczt,
      pageIndex: params.page - 1,
      limit: params.pageSize,
      orderBy: 0,
      districts: buildDistricts(params['districts_']),
      ...params,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
// .then((x) => {
//   console.log('@x===', x);
// })

// 107村庄消防安全排查 -- 查询接口
export const villageListApi107 = (params: DemoParams) =>
  defHttp.post<DemoListGetResultModel>({
    url: Api.VILLAGE_LIST_314,
    data: {
      pczt: params.pczt,
      pageIndex: params.page - 1,
      limit: params.pageSize,
      check315: params.check315,
      type: 107,
      orderBy: 0,
      districts: buildDistricts(params['districts_']),
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
// 导出
// export const exportApi = (params: DemoParams) =>
//   defHttp.post<DemoListGetResultModel>({
//     url: Api.VILLAGE_EXPORT,
//     data: {
//       pczt: 0,
//       text: 'string',
//       orderDesc: true,
//       pageIndex: 1,
//       limit: 0,
//       check315: 0,
//       type: 107,
//       orderBy: 0,
//       districts: buildDistricts(params['districts_']),
//     },
//     headers: {
//       // @ts-ignore
//       ignoreCancelToken: true,
//     },
//   });

// 777村庄消防安全排查 -- 查询接口
export const villageListApi777 = (params: DemoParams) =>
  defHttp.post<DemoListGetResultModel>({
    url: Api.VILLAGE_LIST_314,
    data: {
      pczt: params.pczt,
      pageIndex: params.page - 1,
      limit: params.pageSize,
      check315: params.check315,
      type: 777,
      orderBy: 0,
      districts: buildDistricts(params['districts_']),
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });

export const hiddenDangerStatApi = (type: number) =>
  defHttp.get(
    { url: '/houses/hidden-danger/stat', params: { type: type } },
    { errorMessageMode: 'none' },
  );

export const hiddenDangerStatApiOter = (type: number) =>
  defHttp.get(
    { url: '/houses/hidden-danger/Oter', params: { type: type } },
    { errorMessageMode: 'none' },
  );

export const getHcHousrDetailApi = (params: any) =>
  defHttp.get({
    url: `/hc/${params.id}/restinfo`,
    params: {
      id: params.id,
    },
    headers: {
      // @ts-ignore
      ignoreCancelToken: true,
    },
  });
